<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="缴费业主" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入缴费业主姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属小区" prop="communityId">
        <el-select v-model="queryParams.communityId"   placeholder="请选择所属小区" filterable clearable size="small" >
          <el-option
            v-for="community in communityOptions"
            :key="community.id"
            :label="community.name"
            :value="Number(community.id)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="缴费流水单号" prop="feeNo">
        <el-input
          v-model="queryParams.feeNo"
          placeholder="请输入缴费流水单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴费时间" >
        <el-date-picker
          clearable size="small"
          v-model="queryParams.startTime"
          type="date"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
          placeholder="选择开始时间">
        </el-date-picker>&ensp;-&ensp;
        <el-date-picker
          clearable size="small"
          v-model="queryParams.endTime"
          type="date"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:communityMonthFee:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="communityMonthFeeList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="流水单号" align="center" prop="feeNo" />
      <el-table-column label="缴费业主" align="center" prop="ownerName" />
      <el-table-column label="业主电话" align="center" prop="phone" />
      <el-table-column label="小区名称" align="center" prop="communityName" />
      <el-table-column label="单元名称" align="center" prop="unitName" />
      <el-table-column label="门牌号" align="center" prop="doorNum" />
      <el-table-column label="缴费金额" align="center" prop="payPrice" >
        <template slot-scope="scope">
          <span>{{ scope.row.payPrice / 100 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收费备注" align="center" prop="remark" />
      <el-table-column label="缴费时间" align="center" prop="createtime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期至" align="center" prop="validityPeriod" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validityPeriod) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listCommunityMonthFee, exportCommunityMonthFee } from "@/api/system/communityMonthFee";
import {getAllList} from "@/api/system/community";

export default {
  name: "CommunityMonthFee",
  components: {
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物业缴费记录 表格数据
      communityMonthFeeList: [],
      //小区下拉列表
      communityOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      pickerOptions: {
        disabledDate(time){
          return time.getTime() > Date.now()
        }
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ownerName: undefined,
        communityId: undefined,
        feeNo: undefined,
        startTime: undefined,
        endTime: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getCommunityList();
  },
  methods: {
    /** 查询物业缴费记录 列表 */
    getList() {
      this.loading = true;
      listCommunityMonthFee(this.queryParams).then(response => {
        this.communityMonthFeeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //获取小区列表
    getCommunityList(){
      let data={};
      getAllList(data).then(response => {
        this.communityOptions = response.data
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        ownerId: undefined,
        communityId: undefined,
        feeNo: undefined,
        payPrice: undefined,
        remark: undefined,
        createtime: undefined,
        validityPeriod: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.compareTime(this.queryParams.startTime,this.queryParams.endTime) == false){
        this.msgError("请选择正确的时间段");
        return false;
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有物业缴费记录 数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportCommunityMonthFee(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
